package com.company.blockqueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 * @description: SynchronousQueue在 put()的阻塞过程
 * @author: ruoan
 * @date: 2020/12/10 23:31
 */
public class SynchronizedBlockingQueue {


    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> queue  = new SynchronousQueue<>();

        new Thread(()->{
            try {
                queue.put("i");
                System.out.println(Thread.currentThread().getName()+"放入i");
                queue.put("j");
                System.out.println(Thread.currentThread().getName()+"放入j");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        },"t1").start();
        //
        //new Thread(()->{
        //    try {
        //        Thread.sleep(3000);
        //        System.out.println("取值");
        //        System.out.println(queue.take());
        //    } catch (InterruptedException e) {
        //        e.printStackTrace();
        //    }
        //
        //
        //},"t2").start();


    }
}
